Skip to content

Conversation

@artagnon
Copy link
Contributor

getContextInst currently returns an invalid union field, when it is called with a ConditionFact, although existing callers don't do this. In order to error out early and serve as documentation for future callers, add an assert forbidding the behavior.

getContextInst currently returns an invalid union field, when it is
called with a ConditionFact, although existing callers don't do this. In
order to error out early and serve as documentation for future callers,
add an assert forbidding the behavior.
@llvmbot
Copy link
Member

llvmbot commented Nov 12, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Ramkumar Ramachandra (artagnon)

Changes

getContextInst currently returns an invalid union field, when it is called with a ConditionFact, although existing callers don't do this. In order to error out early and serve as documentation for future callers, add an assert forbidding the behavior.


Full diff: https://github.com/llvm/llvm-project/pull/115898.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/ConstraintElimination.cpp (+1)
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 7c06e0c757e1cc..d2e532d29d07b5 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -164,6 +164,7 @@ struct FactOrCheck {
   }
 
   Instruction *getContextInst() const {
+    assert(!isConditionFact());
     if (Ty == EntryTy::UseCheck)
       return getContextInstForUse(*U);
     return Inst;

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@artagnon artagnon merged commit 856c47b into llvm:main Nov 13, 2024
10 checks passed
@artagnon artagnon deleted the ce-contextinst-assert branch November 13, 2024 12:05
@fhahn
Copy link
Contributor

fhahn commented Nov 13, 2024

Thanks for adding the assert!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants